//
//  HomADCell.m
//  CarUser
//
//  Created by 王森林 on 2018/11/30.
//  Copyright © 2018年 王森林. All rights reserved.
//

#import "HomADCell.h"
#import "SDCycleScrollView.h"
#import "Car_CarDetailViewController.h"
@interface HomADCell()<SDCycleScrollViewDelegate>
@property (strong, nonatomic) SDCycleScrollView *mScrollView;
@property (nonatomic, strong) NSArray *dataArr;
@end

@implementation HomADCell

- (void)createUI
{
    self.mScrollView = ({
        SDCycleScrollView *scrollView = [[SDCycleScrollView alloc] initWithFrame:CGRectZero];
        scrollView.backgroundColor = [UIColor whiteColor];
        scrollView.delegate = self;
        scrollView.imageURLStringsGroup = @[];
        scrollView.pageDotColor = [UIColor whiteColor];
        scrollView.currentPageDotColor = KRGB(255, 255, 255, 0.6);
        [self addSubview:scrollView];
        scrollView;
    });
    
    [self.mScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
    
}

- (void)setData:(id)data
{
    if (data) {
        self.dataArr = [NSArray arrayWithArray:data];
        NSMutableArray *imgsAry = [[NSMutableArray alloc] init];
        [self.dataArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSDictionary *dict = [self.dataArr objectAtIndex:idx];
            [imgsAry addObject:APPEND_URL(BASE_URL, [dict objectForKey:@"IMGURL"])];
        }];
        
        self.mScrollView.imageURLStringsGroup  =  imgsAry;
    }
 
    
}

//- (void)setDataAry:(NSArray *)dataAry
//{
//    self.mScrollView.imageURLStringsGroup  =  dataAry;
//
//}

/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    
      NSDictionary *dict = [self.dataArr objectAtIndex:index];
      NSLog(@"dict%@",dict);
    NSString *type = [dict objectForKey:@"APPTYPE"];
    if (type.integerValue == 1) {
        //文章详情
    }
    
    if (type.integerValue == 2) {
        //车辆详情
        Car_CarDetailViewController *push = [[Car_CarDetailViewController alloc]init];
        push.SERIES_ID = [dict objectForKey:@"APPURL"];
        [[self viewController].navigationController pushViewController:push animated:YES];
        
    }
    
    
}

/** 图片滚动回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index {
    
}
@end
